<template>
  <div class="app-container">
    <div class="filter-container">
      <!--        <el-input v-model="listQuery.student_no" clearable placeholder="学号" style="width: 150px" class="filter-item"/>-->
      <!--        <el-button type="primary" class="filter-item" @click="handleFilter">搜索</el-button>-->
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border highlight-current-row>
      <el-table-column label="ID">
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column label="学号">
        <template slot-scope="scope">{{ scope.row.student_no }}</template>
      </el-table-column>
      <el-table-column label="姓名">
        <template slot-scope="scope">{{ scope.row.username }}</template>
      </el-table-column>
      <el-table-column label="专业">
        <template slot-scope="scope">{{ scope.row.zhuanye }}</template>
      </el-table-column>
      <el-table-column label="宿舍">
        <template slot-scope="scope">{{ scope.row.room }}</template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope"> {{ scope.row.status !== 6 ? '未处理' : '已处理' }}</template>
      </el-table-column>
      <el-table-column label="申请理由">
        <template slot-scope="scope">{{ scope.row.reason }}</template>
      </el-table-column>
      <el-table-column label="申请时间">
        <template slot-scope="scope">{{ scope.row.create_time }}</template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.status == 6" type="primary" size="mini" @click="handleReview(scope.row)">
            {{ scope.row.status != 6 ? '未处理' : '已处理' }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fetchData"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getApplyList, saveChange } from '@/api/room'
export default {
  name: 'Apply',
  components: { Pagination },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 20
      },
      list: [],
      listLoading: true,
      dialogVisible: false,
      total: 0
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      getApplyList(this.listQuery).then(res => {
        this.listLoading = false
        this.list = res.data.list
        this.total = res.data.total
      })
    },
    handleReview(row) {
      this.$confirm('是否确认安排更换宿舍？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        saveChange(row).then(response => {
          this.$notify({
            title: '成功',
            message: '处理成功',
            type: 'success',
            duration: 2000
          })
          this.fetchData()
        })
      }).catch(() => {
        this.$message({
          message: '已取消',
          type: 'info'
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
